package com.huwei.activemq.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.jms.Queue;
import javax.jms.Topic;

/**
 * @Author: 胡伟
 * @Date: 2021/1/13 18:10
 * @Description:
 */
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Resource(name = "huwei_queue")
    private Queue huweiQueue;

    @Resource(name = "jiahong_queue")
    private Queue jiahongQueue;

    @Resource(name = "huwei_topic")
    private Topic huweiTopic;

    @GetMapping("sendMsg")
    public String sendMessage(@RequestParam("msg") String msg) {
        System.out.println(Thread.currentThread().getName()+"-----"+Thread.currentThread().getThreadGroup());
        jmsMessagingTemplate.convertAndSend(huweiQueue, msg);
        return "success";
    }

    @GetMapping("sendMsg1")
    public String sendMessage1(@RequestParam("msg") String msg) {
        jmsMessagingTemplate.convertAndSend(jiahongQueue, msg);
        return "success";
    }
}
